package com.tian.print.login.presenter;

import android.arch.lifecycle.LifecycleOwner;

import com.tian.print.app.BasePresenter;
import com.tian.print.bean.UserInfo;
import com.tian.print.http.error.ApiException;
import com.tian.print.login.contract.ILoginContract;
import com.tian.print.login.model.LoginModel;

/**
 * Description:
 * <br>Author：tian
 * <br>Time: 2019/5/24 17:35
 */
public class LoginPresenter extends BasePresenter implements ILoginContract.ILoginPresenter, LoginModel.OnLoginFinishedListener {

    private LoginModel mLoginModel;
    private ILoginContract.ILoginView mLoginView;

    public LoginPresenter(ILoginContract.ILoginView loginView) {
        mLoginView = loginView;
        mLoginModel = new LoginModel(this);
    }

    @Override
    public void login(String userName, String password) {
        mLoginModel.login(userName, password);
    }

    @Override
    protected void onDestory(LifecycleOwner owner) {
        mLoginModel.cancelRequest();
    }

    @Override
    public void loginSuccess(UserInfo userInfo) {
        mLoginView.onLoginSuceess(userInfo);
    }

    @Override
    public void loginError(ApiException e) {
        mLoginView.onLoginError(e);
    }


}
